package com.snake.springboot.custom.service.aspect;


import com.snake.springboot.custom.api.model.base.CustPointsFreezeModel;
import com.snake.springboot.custom.api.model.points.PointsChangeModel;
import com.snake.springboot.custom.api.service.base.CustPointsExpireService;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.snake.common.utils.JsonUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <p>算力切面
 * 类{@code PointsAspect} </br>
 * 创建时间2025/5/5 18:55
 * @author yangxt
 * @see
 */
@Aspect
@Component
public class PointsExpireAspect {
    @Resource
    private CustPointsExpireService expireService;

    /**
     * 添加关系
     */
    @AfterReturning(value = "execution(* com.snake.springboot.custom.api.service.base.CustPointsService.add(..))&& args(model)")
    public void add(PointsChangeModel model){
        try {
        expireService.add(model);
        }catch (Exception e){
        }
    }

    @AfterReturning(value = "execution(* com.snake.springboot.custom.api.service.base.CustPointsService.reduce(..))&& args(model)")
    public void reduce(PointsChangeModel model){
        try {
            expireService.reduce(model.getCustomId(),model.getChangePoints());
        }catch (Exception e){
        }

    }

    @AfterReturning(value = "execution(* com.snake.springboot.custom.service.impl.base.CustPointsServiceImpl.reduceFreeze(..))&& args(model)",returning = "methodResult")
    public void reduceFreeze(CustPointsFreezeModel model, Boolean methodResult) {
        if (!methodResult) {
            return;
        }
        try {
            expireService.reduce(model.getCustomId(), model.getPoints());
        } catch (Exception e) {
        }
    }
}
